<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class downloadAction extends sfActions{
	public function execute(){
        $this->page = $this->getRequestParameter('page', 1);
        $this->phoneNumber = trim($this->getRequestParameter('phone_number', ""));
        if($this->phoneNumber != ""){$this->phoneNumber = iringback::checkPhoneNumber($this->phoneNumber)->phone;}
        $this->downloadSource = trim($this->getRequestParameter('download_source', "All"));
        $this->createdDatetimeFrom = $this->getRequestParameter('created_datetime_from', "");
        $this->createdDatetimeTo = $this->getRequestParameter('created_datetime_to', "");
        $createdDatetimeFrom = strtotime($this->createdDatetimeFrom);
        $createdDatetimeTo = strtotime($this->createdDatetimeTo);
        $limit = sfConfig::get('customer_care_limit');
        $offset = ($this->page-1)*$limit;
        $c = new Criteria();
        $c->setLimit($limit);
        //$this->download = null;
        
        $this->download = RingtoneDownloadPeer::getDownload($this->phoneNumber,$this->downloadSource, $createdDatetimeFrom, $createdDatetimeTo, $limit, $offset);
        $this->totalDownload = RingtoneDownloadPeer::getTotalDownload($this->phoneNumber,$this->downloadSource, $createdDatetimeFrom, $createdDatetimeTo);
       
        /*
        if($this->downloadSource == 'web'){
            //$this->download = SmsOutputPeer::getSms($this->phoneNumber, $createdDatetimeFrom, $createdDatetimeTo, $limit, $offset);
            //$this->totalDownload = SmsOutputPeer::getTotalSms($this->phoneNumber, $createdDatetimeFrom, $createdDatetimeTo);
        }elseif($this->downloadSource == 'wap'){
            //$this->download = SmsInputPeer::getSms($this->phoneNumber, $createdDatetimeFrom, $createdDatetimeTo, $limit, $offset);
            //$this->totalDownload = SmsInputPeer::getTotalSms($this->phoneNumber, $createdDatetimeFrom, $createdDatetimeTo);
        }
        */
        $this->totalPage = intval($this->totalDownload/$limit);
        if($this->totalPage%$limit > 0){
            $this->totalPage = $this->totalPage +1;
        }
    }
}
?>
